﻿@using LunwenYun.Infrastructure.Entities.Entity;
@using LunwenYun.Infrastructure.Entities.Enum;
@using LunwenYun.Tool.Configration;
@{
    User user = null;
    if (HttpContext.Current.User.Identity.IsAuthenticated)
    {
        user = new User().Find(HttpContext.Current.User.Identity.Name);
    }

    if (user != null && user.SystemRole == LunwenYun.Infrastructure.Entities.Enum.UserRole.PaperAgent)
    {
        Layout = "~/Views/Shared/_o_Main.cshtml";
    }
    else
    {
        Layout = "~/Views/Shared/_m_Main.cshtml";
    }

    Article article = ViewBag.Article;
    ViewBag.Title = SiteResource.SiteName + " -- " + article.Title;
}
<div class="mini-layout graybg">
    <div class="row">
        <div class="span9">
            <h4>
                <a>@article.Title</a>
                @if (article.Status == ArticleStatus.Complete)
                { 
                    <span class="badge badge-important">已完成</span>
                }
                else if (article.ExpireTime < DateTime.Now)
                {
                    <span class="badge">已结束</span>
                }
                else
                { 
                    <span class="badge badge-success">进行中</span>
                }
            </h4>
            <hr />
            <p style="width: 90%;">
                <a>摘要</a> @article.Abstract
            </p>
            <ul class="nav nav-tabs margin-top">
                <li class="active"><a href="#tab1" data-toggle="tab">约稿动态</a></li>
            </ul>
            <div class="tab-content">
                <div class="tab-pane active" id="tab1">
                    <table class="table table-hover">
                        <tbody>
                            @{
                                ItemListBox<MessageBoard> messageBoard = ViewBag.MessageBoard;
                                if (messageBoard != null && messageBoard.Data != null && messageBoard.Data.Any())
                                {
                                    foreach (var item in messageBoard.Data)
                                    {
                                <tr style="min-height: 150px; height: auto;">
                                    <td>
                                        <div class="pull-left" style="width: 100px; height: 85px;">
                                            <div class="doc">
                                                <img alt="@item.AgentInfo.Name" src="/content/img/pho.png" /></div>
                                        </div>
                                        <div class="pull-right" style="width: 80%;">
                                            <h5>
                                                @item.AgentInfo.Name，留言：</h5>
                                            <p>
                                                @Html.Raw(item.Message)
                                            </p>
                                        </div>
                                    </td>
                                    <td style="width: 20%; text-align: right" class="center">
                                        @if (article.UserName.ToLower() == HttpContext.Current.User.Identity.Name.ToString())
                                        {
                                            <a target="_blank" href="http://wpa.qq.com/msgrd?v=3&amp;uin=@item.AgentInfo.QQ&amp;site=qq&amp;menu=yes">
                                                <img border="0" src="http://wpa.qq.com/pa?p=2:@item.AgentInfo.QQ:41" alt="点击这里给我发消息" title="点击这里给我发消息" />
                                            </a>
                                            <br />
                                            <a style="margin-top:5px" href="/m/tolaunch/@article.Id?messageId=@item.Id" class="btn btn-info btn-mini">
                                                发起约稿</a>
                                        }
                                        @if (user != null && user.SystemRole == UserRole.Admin)
                                        {
                                            <a href="javascript:;" onclick="deletethis(@item.Id,this)" class="btn btn-error btn-mini">
                                                删除此留言</a>
                                        }
                                    </td>
                                </tr>
                                    }
                                }
                            }
                        </tbody>
                    </table>
                    @Html.Raw(messageBoard.PageItemSegment)
                </div>
            </div>
            @if (user == null || user.SystemRole == UserRole.PaperAgent)
            {
                <hr />
                <div class="tab-content">
                    <form id="messageform" method="post" action="/j/postmessage">
                    <input type="hidden" name="id" value="@article.Id" />
                    <div class="control-group">
                        <label class="control-label">
                            留言：</label>
                        <div class="controls">
                            <textarea rows="10" id="txtMessage" class="span9" name="Message"></textarea>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">
                        </label>
                        <div class="controls">
                            @if (user == null)
                            { 
                                <input type="button" disabled="disabled" class="btn btn-primary btn-large" value="请先登录" />
                            }
                            else if (user.SystemRole == UserRole.PaperAgent)
                            {
                                if (!user.IsComplete)
                                { 
                                <a href="/o/profile?ret=@Request.RawUrl" class="btn btn-primary btn-large">请完善约稿人信息</a>
                                }
                                else
                                {
                                <input type="button" onclick="doPost()" class="btn btn-primary btn-large" value="确定" />
                                }
                            }
                            <span style="color: Red;" id="labmsg"></span>
                        </div>
                    </div>
                    </form>
                </div>
            }
        </div>
        <div class="span2">
            <p>
                行业： @article.IndType.Mapping()</p>
            @if (!String.IsNullOrEmpty(article.Aptitude))
            {
                string aptString = string.Empty;
                List<string> apt = article.Aptitude.Split(';').Where(c => !String.IsNullOrEmpty(c)).ToList();
                foreach (var aptitem in apt)
                {
                    try
                    {
                        int iapt = Int32.Parse(aptitem);
                        aptString += ((Aptitude)iapt).Mapping() + "、";
                    }
                    catch { }
                }
                aptString = aptString.EndsWith(";") ?
                    aptString.Remove(aptString.Length) : aptString;
                <p>
                    方向： @aptString</p>
            }
            <p>
                预算： @article.PriceRange</p>
            <p>
                投稿时间： @article.CreateTime.ToString("yyyy-MM-dd")</p>
            <p>
                联系投稿人：
                @if (!String.IsNullOrEmpty(article.QQ))
                { 
                    <a target="_blank" href="http://wpa.qq.com/msgrd?v=3&amp;uin=@article.QQ&amp;site=qq&amp;menu=yes">
                        <img border="0" src="http://wpa.qq.com/pa?p=2:@article.QQ:41" alt="点击这里给我发消息" title="点击这里给我发消息" />
                    </a>
                }
            </p>
            <hr />
            @if (!(user != null && user.SystemRole == UserRole.Member))
            {
                <div style="text-align: center">
                    <a href="javascript:;" onclick="toMessage()" class="btn btn-primary btn-large" style="width: 55%">
                        约稿留言</a>
                </div>
            }
            @{
                if ((user == null || user.SystemRole == UserRole.PaperAgent) &&
                article.ExpireTime > DateTime.Now && article.Status == ArticleStatus.OnShow)
                { 
                <br />
                <div style="text-align: center">
                    <a href="/o/launch/@article.Id" class="btn btn-info btn-large" style="width: 55%">联系约稿</a>
                </div>
                }}
        </div>
    </div>
</div>
@section tail
{
    <script type="text/javascript">
        function toMessage() {
            $('#txtMessage').focus();
        }
        function doPost() {
            var msg = $('#txtMessage').val();
            if (msg == '') {
                $('#labmsg').text('请输入留言内容');
                return;
            }
            if (msg.length <= 20) {
                $('#labmsg').text('输入的留言内容不得少于20个字符');
                return;
            }
            $('#messageform').submit();
        }
    </script>
    @if (user != null && user.SystemRole == UserRole.Admin)
    {
        <script type="text/javascript">
            function deletethis(id, sender) {
                if (confirm('您确认删除此留言吗？')) {
                    $.ajax({
                        url: '/j/deletemessage',
                        data: { id: id },
                        success: function (res) {
                            if (res == 1) {
                                $(sender).parent().parent().remove();
                            }
                        }
                    });
                }
            }
        </script>
    }
}
